package com.debao.quartz.task;

import cn.hutool.core.date.DateUtil;
import com.debao.common.constant.ConfigConstants;
import com.debao.common.constant.WechatConstants;
import com.debao.common.core.domain.entity.SysUser;
import com.debao.common.wechat.WechatUtils;
import com.debao.system.service.IConfigService;
import com.debao.system.service.ISysUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


@Component("user")
public class UserTask {

    @Resource
    private IConfigService configService;
    @Resource
    private ISysUserService userService;


    public static void main(String[] args) {
        System.out.printf("22 "+   DateUtil.isLastDayOfMonth(new Date()));
    }

    /**
     * 更新token
     */
    public void resetPostNumber() {
        // 是否月底
        boolean isLastDay = DateUtil.isLastDayOfMonth(new Date());
        if(!isLastDay){
            return;
        }
        // 提交次数
        String postNumber = configService.selectValueByKey(ConfigConstants.USER_POST);
        if (postNumber == null && postNumber.isEmpty()) {
            return;
        }
        // 用户列表
        List<SysUser> userList = userService.selectUserList(new SysUser());
        userList.forEach(u -> {
            // 更新用户的提交次数
            u.setPostNumber(Integer.valueOf(postNumber));
            userService.updateUser(u);
        });
    }
}
